package com.lagou.client;

import com.lagou.model.Student;
import com.lagou.model.StudentMessage;
import com.lagou.model.User;
import com.lagou.model.UserMessage;

import java.io.IOException;

public class LoginClient {
    /**
     管理员考试模块页面
     */
    public void clientManagerLogin(ClientInitClose cic,ClientView clientView) throws IOException, ClassNotFoundException {
        System.out.println("请输入管理员的账户信息：");
        String userName = ClientScanner.getScanner().next();
        System.out.println("请输入管理员的密码信息：");
        String password = ClientScanner.getScanner().next();
        UserMessage tum = new UserMessage("managerCheck", new User(userName, password));
        // 2.将UserMessage类型的对象通过对象输出流发送给服务器
        cic.getOos().writeObject(tum);
        System.out.println("客户端发送管理员账户信息成功！");
        // 3.接收服务器的处理结果并给出提示
        tum = (UserMessage) cic.getOis().readObject();
        if ("success".equals(tum.getType())) {
            System.out.println("登录成功，欢迎使用！");
            clientView.ManagerPage();
        } else {
            System.out.println("用户名或密码错误！");
        }
    }


    /**
     * 自定义成员方法实现客户端学员员登录的功能
     */
   public void clientStudentLogin(ClientInitClose cic,ClientView clientView) throws IOException, ClassNotFoundException {
        System.out.println("请输入学员的学号信息：");
       int id= ClientScanner.getScanner().nextInt();
        System.out.println("请输入学员的密码信息：");
        String password = ClientScanner.getScanner().next();
       StudentMessage sm=new StudentMessage(new Student(id,password), "studentCheck");
        // 2.将UserMessage类型的对象通过对象输出流发送给服务器
        cic.getOos().writeObject(sm);
        // 3.接收服务器的处理结果并给出提示
        sm = (StudentMessage) cic.getOis().readObject();
        if ("success".equals(sm.getType())) {
            System.out.println("登录成功，欢迎使用！");
            clientView.userPage();
        } else {
            System.out.println("用户名或密码错误！");
        }
   }
    public void managerOfStu(ClientInitClose cic,ClientView clientView) throws IOException, ClassNotFoundException {
       cic.getOos().writeChar('S');
       cic.getOos().flush();
        clientView.studentPage();
    }
    public void managerOfExm(ClientInitClose cic,ClientView clientView) throws IOException, ClassNotFoundException {
        cic.getOos().writeChar('E');
        cic.getOos().flush();
        clientView.examModuleOfMan();
    }
    public void quit(ClientInitClose cic,ClientView clientView) throws IOException {
        cic.getOos().writeChar('Q');
    }


}
